package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 修改用户密码
 */
public class JDBCDemo03 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                    "root",
                    "root"
            );
            System.out.println("与数据库连接成功");
            Statement statement = connection.createStatement();
            //UPDATE userinfo SET password='555666' WHERE username='jerry';
            String sql = "UPDATE userinfo SET password='555666' WHERE username='jerry';";
            int num = statement.executeUpdate(sql);
            if (num>0)
                System.out.println("密码修改成功");
            else
                System.out.println("密码修改失败");
            statement.executeQuery("");
            connection.close();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }
}
